clear all
* Do file Business Cycles Latam Dollarized Economies
import excel "C:\Users\Daniele\Documents\My New Papers & Books\Paper_3 SBVAR dollarized economies\Original_data_bsvar\full_database_bsvar.xlsx", sheet("Sheet1") firstrow
tsset Date, yearly
quietly summ FDIY_SLV
replace FDIY_SLV = r(mean) if FDIY_SLV == .
gen lus = ln(USY)
gen lcom = ln(COMPI)
tsfilter hp hp_us hp_com = lus lcom, smooth(100)
label variable hp_us "Output gap US"
label variable hp_com "Commodities Index Price"
foreach i in ECU SLV PAN {
	gen tot_`i' = PX_`i' / PM_`i'
	gen fdi_`i' = (FDIY_`i'/100)*Y_`i'
	gen REM_`i' = (REMY_`i'/100)*Y_`i'
	gen G_`i' = (GY_`i'/100)*Y_`i'
	gen C_`i' = (CY_`i'/100)*Y_`i'
	gen I_`i' = (IY_`i'/100)*Y_`i'	
	gen lrem_`i' = ln(REM_`i')
	gen lg_`i' = ln(G_`i')
	gen ly_`i' = ln(Y_`i')
	gen lc_`i' = ln(C_`i')
	gen li_`i' = ln(I_`i')
	tsfilter hp hp_rem_`i' hp_tot_`i' hp_fdi_`i' hp_TFP_`i' hp_g_`i' hp_x_`i' hp_c_`i' hp_i_`i' = lrem_`i' tot_`i' fdi_`i' TFP_`i' lg_`i' ly_`i' lc_`i' li_`i', smooth(100)
	order hp_rem_`i' hp_tot_`i' hp_fdi_`i' hp_TFP_`i' hp_g_`i' hp_x_`i' hp_c_`i' hp_i_`i', after(Date)
	label variable hp_rem_`i' "Remittances `i' "
	label variable hp_tot_`i' "Terms of Trade `i' "
	label variable hp_fdi_`i' "Foreign Direct Investments `i' "
	label variable hp_TFP_`i' "Total Factor Productivity `i' "
	label variable hp_g_`i' "Government Spending `i' "
	label variable hp_x_`i' "Output Gap `i' "
	label variable hp_c_`i' "Household Consumption `i' "
	label variable hp_i_`i' "Domestic Investments `i' "
}
order hp_us hp_com, after(Date)

*Estimates bsvar Ecuador

gen dol_ECU = 0
replace dol_ECU = 1 if Date > 1999
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_ECU hp_tot_ECU hp_fdi_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(dol_ECU) lags(1/1)
bayesvarstable
estimates store bsvarecu1
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_ECU hp_tot_ECU hp_fdi_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(dol_ECU) lags(1/2)
bayesvarstable
estimates store bsvarecu2
bayestest model bsvarecu1 bsvarecu2 
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_ECU hp_tot_ECU hp_fdi_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(dol_ECU) lags(1/1)
bayesstats summary {hp_x_ECU:dol_ECU}
irf set birfdol1, replace
bayesirf create varecu, step(10) replace
bayesirf table oirf, impulse(hp_us hp_com hp_rem_ECU hp_tot_ECU hp_fdi_ECU hp_TFP_ECU hp_g_ECU hp_c_ECU hp_i_ECU) response(hp_x_ECU) median noci
bayesirf table fevd, response(hp_x_ECU) noci

*Estimates bsvar El Salvador

gen dol_SLV = 0
replace dol_SLV = 1 if Date > 2000
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_SLV hp_tot_SLV hp_fdi_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(dol_SLV) lags(1/1)
bayesvarstable
estimates store bsvarslv1
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_SLV hp_tot_SLV hp_fdi_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(dol_SLV) lags(1/2)
bayesvarstable
estimates store bsvarslv2
bayestest model bsvarslv1 bsvarslv2
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_SLV hp_tot_SLV hp_fdi_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(dol_SLV) lags(1/1)
bayesstats summary {hp_x_SLV:dol_SLV}
irf set birfdol1, replace
bayesirf create varslv, step(10) replace
bayesirf table oirf, impulse(hp_us hp_com hp_rem_SLV hp_tot_SLV hp_fdi_SLV hp_TFP_SLV hp_g_SLV hp_c_SLV hp_i_SLV) response(hp_x_SLV) median noci
bayesirf table fevd, response(hp_x_SLV) noci

*Estimates bsvar Panama

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_PAN hp_tot_PAN hp_fdi_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, lags(1/1)
bayesvarstable
estimates store bsvarpan1
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_PAN hp_tot_PAN hp_fdi_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, lags(1/2)
bayesvarstable
estimates store bsvarpan2
bayestest model bsvarpan1 bsvarpan2
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_PAN hp_tot_PAN hp_fdi_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, lags(1/1)
irf set birfdol1, replace
bayesirf create varpan, step(10) replace
bayesirf table oirf, impulse(hp_us hp_com hp_rem_PAN hp_tot_PAN hp_fdi_PAN hp_TFP_PAN hp_g_PAN hp_c_PAN hp_i_PAN) response(hp_x_PAN) median noci
bayesirf table fevd, response(hp_x_PAN) noci

*Sensitivity Analysis

*Ecuador

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_x_ECU hp_rem_ECU hp_tot_ECU hp_fdi_ECU hp_TFP_ECU hp_g_ECU hp_c_ECU hp_i_ECU, exog(dol_ECU) lags(1/1)
irf set birfdol1, replace
bayesirf create varecu, step(10) replace
bayesirf table fevd, response(hp_x_ECU) noci

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_ECU hp_tot_ECU hp_fdi_ECU hp_TFP_ECU hp_g_ECU hp_c_ECU hp_i_ECU hp_x_ECU, exog(dol_ECU) lags(1/1)
bayesirf create varecu, step(10) replace
bayesirf table fevd, response(hp_x_ECU) noci

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(hp_us hp_com hp_rem_ECU hp_fdi_ECU dol_ECU) lags(1/1)
estimates store sensecu1
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(hp_us hp_com hp_rem_ECU hp_fdi_ECU dol_ECU) lags(1/2)
estimates store sensecu2
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(hp_us hp_com hp_rem_ECU hp_fdi_ECU dol_ECU) lags(1/3)
estimates store sensecu3
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(hp_us hp_com hp_rem_ECU hp_fdi_ECU dol_ECU) lags(1/4)
estimates store sensecu4
bayestest model sensecu1 sensecu2 sensecu3 sensecu4 

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_ECU hp_TFP_ECU hp_g_ECU hp_x_ECU hp_c_ECU hp_i_ECU, exog(hp_us hp_com hp_rem_ECU hp_fdi_ECU dol_ECU) lags(1/1)
bayesirf create varecu, step(10) replace
bayesirf table fevd, response(hp_x_ECU) noci

*El Salvador

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_x_SLV hp_rem_SLV hp_tot_SLV hp_fdi_SLV hp_TFP_SLV hp_g_SLV hp_c_SLV hp_i_SLV, exog(dol_SLV) lags(1/1)
irf set birfdol1, replace
bayesirf create varslv, step(10) replace
bayesirf table fevd, response(hp_x_SLV) noci

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_SLV hp_tot_SLV hp_fdi_SLV hp_TFP_SLV hp_g_SLV hp_c_SLV hp_i_SLV hp_x_SLV, exog(dol_SLV) lags(1/1)
bayesirf create varslv, step(10) replace
bayesirf table fevd, response(hp_x_SLV) noci

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(hp_us hp_com hp_rem_SLV hp_fdi_SLV dol_SLV) lags(1/1)
estimates store senslv1
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(hp_us hp_com hp_rem_SLV hp_fdi_SLV dol_SLV) lags(1/2)
estimates store senslv2
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(hp_us hp_com hp_rem_SLV hp_fdi_SLV dol_SLV) lags(1/3)
estimates store senslv3
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(hp_us hp_com hp_rem_SLV hp_fdi_SLV dol_SLV) lags(1/4)
estimates store senslv4
bayestest model senslv1 senslv2 senslv3 senslv4
 
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_SLV hp_TFP_SLV hp_g_SLV hp_x_SLV hp_c_SLV hp_i_SLV, exog(hp_us hp_com hp_rem_SLV hp_fdi_SLV dol_SLV) lags(1/2)
bayesirf create varslv, step(10) replace
bayesirf table fevd, response(hp_x_SLV) noci

*Panama

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_x_PAN hp_rem_PAN hp_tot_PAN hp_fdi_PAN hp_TFP_PAN hp_g_PAN hp_c_PAN hp_i_PAN, lags(1/1)
irf set birfdol1, replace
bayesirf create varpan, step(10) replace
bayesirf table fevd, response(hp_x_PAN) noci

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_us hp_com hp_rem_PAN hp_tot_PAN hp_fdi_PAN hp_TFP_PAN hp_g_PAN hp_c_PAN hp_i_PAN hp_x_PAN, lags(1/1)
bayesirf create varpan, step(10) replace
bayesirf table fevd, response(hp_x_PAN) noci

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, exog(hp_us hp_com hp_rem_PAN hp_fdi_PAN) lags(1/1)
estimates store senspan1
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, exog(hp_us hp_com hp_rem_PAN hp_fdi_PAN) lags(1/2)
estimates store senspan2
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, exog(hp_us hp_com hp_rem_PAN hp_fdi_PAN) lags(1/3)
estimates store senspan3
quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, exog(hp_us hp_com hp_rem_PAN hp_fdi_PAN) lags(1/4)
estimates store senspan4
bayestest model senspan1 senspan2 senspan3 senspan4

quietly bayes, minnconjprior(selftight(1) lagdecay(0.5) exogtight(1)) rseed(11) saving(bsvar1, replace) : var hp_tot_PAN hp_TFP_PAN hp_g_PAN hp_x_PAN hp_c_PAN hp_i_PAN, exog(hp_us hp_com hp_rem_PAN hp_fdi_PAN) lags(1/1)
bayesirf create varpan, step(10) replace
bayesirf table fevd, response(hp_x_PAN) noci

